<!DOCTYPE html>
<html lang="en-US" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8"/>
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"/>
    <meta name="apple-mobile-web-app-capable" content="yes"/>
    <meta name="apple-mobile-web-app-status-bar-style" content="black"/>
    <meta name="format-detection" content="telephone=no"/>
    <link rel="stylesheet" th:href="@{/layui.css}" href="/layui.css">
    <title>购买支付</title>
    <style>
        ul{
            list-style: none;
        }
        .index_box{
            text-align: center;
            height:100%;
        }
    </style>
</head>

<body style="">
<div class="index_box layui-container">
    <div style="width: 100%;text-align: center">
        <img style="max-width: 750px;width:100%" th:src="${drink.url}" src="http://img.zcool.cn/community/0117e2571b8b246ac72538120dd8a4.jpg@1280w_1l_2o_100sh.jpg" alt="">
    </div>
    <div style="text-align: left;margin:20px 0 40px 10px">
        <b style="font-size: 22px;margin-bottom: 5px;display: inline-block">产品名称</b>
        <p class="layui-text mult_line_ellipsis" style="font-size: 16px;" th:text="${session.order.drinkName}"></p>
        <span th:text="'价格：¥'+ ${session.order.payment}+'元'" class="price" style="font-size: 16px;">¥ 9.9 元</span>
    </div>
    <span class="layui-btn layui-btn-lg layui-btn-fluid" onclick="pay()" style="position: relative;right:0;bottom: 0;background-color: #1e873b;font-size: 22px">点击购买</span>
</div>

<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<!--<script type="text/javascript" src="/js/common.js?t=<%=t%>"></script>-->
<script type="text/javascript">

    // var appId = urlparameter("appid");
    // var timeStamp = urlparameter("timeStamp");
    // var nonceStr = urlparameter("nonceStr");
    // var pg = urlparameter("pg");
    // var signType = urlparameter("signType");
    // var paySign = urlparameter("paySign");

    var appId = "[(${session.appid})]";
    var timeStamp = "[(${session.timeStamp})]";
    var nonceStr = "[(${session.nonceStr})]";
    var pg = "[(${session.pg})]";
    var signType = "[(${session.signType})]";
    var paySign = "[(${session.paySign})]";


    function onBridgeReady() {
        WeixinJSBridge.invoke(
            'getBrandWCPayRequest', {
                "appId": appId, //公众号名称，由商户传入
                "timeStamp": timeStamp, //时间戳，自1970年以来的秒数
                "nonceStr": nonceStr, //随机串
                "package": "prepay_id=" + pg,
                "signType": signType, //微信签名方式:
                "paySign": paySign //微信签名
            },
            function (res) {
                if (res.err_msg == "get_brand_wcpay_request:ok") {
                    alert("支付成功");
                    // window.location.replace("/pay/goToPayOk?mId=" + par.mId + "&userId=" + par.userId);
                    window.location.replace("http://pin1sheng.cn/drink/page/index");
                    // 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回 ok，但并不保证它绝对可靠。
                } else {
                    alert(JSON.stringify(res))
                }
            })
    }

    function pay() {
        if (typeof WeixinJSBridge == "undefined") {
            if (document.addEventListener) {
                document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
            } else if (document.attachEvent) {
                document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
                document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
            }
        } else {
            onBridgeReady();
        }
    }

</script>
</body>
</html>
